#ifndef BJDUBGAME_H_
#define BJDUBGAME_H_

#include "bjproto.h"

#include "bjsaved.h"

class BJShoe;
class BJHand;
class BJConnection;
class BJSavedGame;
class BJRules;
class BJBet;
class BJSideBet;

typedef class BJBet* pBJBet;

class BJGame
{
	private:
		BJRules*	m_pRules;

		int8		m_maxBJBets;
		pBJBet	    m_currentBJBet;
        int8        m_nBJBets;

	public:
		BJGame(BJConnection*, BJRules* pRules, int32* bets, int32* bonus_bets);
		BJGame(BJConnection*, BJRules* pRules, BJSavedGame*);
		~BJGame();

        char    *GetGID( int32 iBJBet ); 

		void	firstDeal( char* pDealScript, int dealScriptLen, BJHand* hand, char who );
		void	DealCard( BJHand* pHand, bool8 faceDown=0, int32 forceHand=0 );
		void	DealCardD( BJHand* pHand, bool8 faceDown=0 );


		void	HandlePlayerAction();
		bool8	HandlePlayerDeal		(int32 *pBonusBalanceBets);
		bool8	HandlePlayerHit			(int32 balance);
		bool8	HandlePlayerStand		();
		bool8	HandlePlayerDouble		(int32 balance);
		bool8	HandlePlayerSplit		(int32 balance);
		bool8	HandlePlayerSurrender	(int32 balance);
		/// [2013-07-09] Charles. Added for supporting 'Zappit Rackcard'.
		bool8 HandlePlayerZap(int32 balance);

		void	HandlePlayerPayout();
		void	HandleDealerResult();

		bool8	IsHardAces();
		bool8	HandlePlayerInsurance(int32 Amt, uint8);
		
		int32	GetBet();
		int32	GetCurrentBet();
		void	sendState(bool8 bRestore);
        BJHand* getDealer() { return dealer; }
		int8	getnBets() { return m_nBJBets; }

		enum Options
		{
			MAXSPLITS = 2
		};

		void save(BJSavedGame*, int8 nextBet);

		bool8	HandlePlayerNextAction(int32 balance);
		void	HandleDealer();
		bool8	HandleDealerNextAction( int32 );
		bool8	HandleDealerHit();
		bool8	HandleDealerStand();
		bool8	CheckEndOfGame();

		bool8	IsLateInsurance();
        pBJBet  nextBJBet();

        // kharmon.  02-13-07.  #16101. 
        void initializeSideBet(int32 anSideBet[BJMAXBETS]);
        void initializeSideBet(BJSavedGame* saved);

		/// [2013-07-09] Charles. Added for supporting 'Zappit Rackcard'.
		bool8 IsZappitRule();

	protected:

		void	EndOfGame();
		void	HandleInsuranceState();

	protected:

		pBJBet		    bjBet[BJMAXBETS];

		BJConnection*	conn;
		BJShoe*			shue;
		BJHand*			dealer;
		bool8			m_dealerPeek;

        ShueSave        m_originalShoe;     // kharmon.  10-23-06.  #16151.  Holds the original shoe settings before any cards were dealt.

        BJSideBet*      m_pSideBet;     // kharmon.  02-13-07.  #16101.  Logic for handling the Perfect Pair sidebets.

		//
		// *IMPORTANT*  When adding/changing here, be sure to update
		//				constructors/destructor, send(), save(), restore()
		//
};

#endif



